package org.iori.luodan.servlet;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.iori.json.JSONHelper;
import org.iori.luodan.base.BaseLogicFactory;
import org.iori.luodan.logic.CategoryLogic;
import org.iori.luodan.logic.GoodsLogic;
import org.iori.luodan.base.BaseServlet;

public class GetRootInfoServlet extends BaseServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1672804482342410902L;
	
	private static CategoryLogic categoryLogic = BaseLogicFactory.getCategoryLogic();
	private static GoodsLogic goodsLogic = BaseLogicFactory.getGoodsLogic();
    
	@Override
	protected String doExcute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		// currentPageを取得する
		Object obj_cat_id = request.getParameter("cat_id");
		int cat_id = 1;
		if (null != obj_cat_id) {
			cat_id = Integer.parseInt(obj_cat_id.toString());
		}
		int start_row = Integer.parseInt(request.getParameter("start_row").toString());
		int row_count = Integer.parseInt(request.getParameter("row_count").toString());
		
		ArrayList goods_contents_list = goodsLogic.getGoodsList(cat_id, start_row, row_count);
		
		int cat_start_row = Integer.parseInt(request.getParameter("cat_start_row").toString());
		int cat_row_count = Integer.parseInt(request.getParameter("cat_row_count").toString());
		
		ArrayList category_contents_list = categoryLogic.getCategoryInfo(cat_start_row, cat_row_count);
		
		HashMap map = new HashMap();
		map.put("goods_contents_list", goods_contents_list);
		map.put("category_contents_list", category_contents_list);
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json;charset=utf-8");
		JSONHelper.writeObject(response, map);
		return null;
	}

}
